package com.wtwd.device.service.impl;

import com.wtwd.device.dao.AppFrequencyMapper;
import com.wtwd.device.dao.SetBloodOxygenWarningMapper;
import com.wtwd.device.model.entity.Frequency;
import com.wtwd.device.model.entity.SetBloodOxygenWarning;
import com.wtwd.device.model.vo.FrequencyAndValueVo;
import com.wtwd.device.service.SetBloodOxygenWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SetBloodOxygenWarningServiceImpl implements SetBloodOxygenWarningService {
    private Integer type = 2;
    @Autowired
    private SetBloodOxygenWarningMapper setBloodOxygenWarningMapper;

    @Autowired
    private AppFrequencyMapper appFrequencyMapper;


    @Override
    public FrequencyAndValueVo getBloodOxygenWarningByDeviceId(Long deviceId) {
        FrequencyAndValueVo frequencyAndValueVo = new FrequencyAndValueVo();
        Frequency frequency = appFrequencyMapper.selectFrequencyByDeviceId(type, deviceId);
        if(frequency != null){
            frequencyAndValueVo.setType(frequency.getType());
            frequencyAndValueVo.setValue(frequency.getValue());
        }
        SetBloodOxygenWarning bloodOxygenWarningByDeviceId = setBloodOxygenWarningMapper.getBloodOxygenWarningByDeviceId(deviceId);
        if(bloodOxygenWarningByDeviceId != null){
            frequencyAndValueVo.setMaxValue(bloodOxygenWarningByDeviceId.getMaxBloodOxygen());
            frequencyAndValueVo.setMinValue(bloodOxygenWarningByDeviceId.getMinBloodOxygen());
        }

        return frequencyAndValueVo;
    }
}
